Implement lazy directives for Ramble - #1756
linsword13 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors Ramble's directive system to support lazy evaluation of directives upon first access using a new DirectiveDictDescriptor descriptor. It removes the need for explicit class-to-instance attribute conversion and updates various base classes to use DirectiveMeta directly as their metaclass. Additionally, comprehensive tests are added to verify lazy evaluation, inheritance, and attribute isolation. The review feedback highlights a critical issue where instance-level modifications to these lazily evaluated directive dictionaries would be lost during cloning or copying. It is recommended to dynamically copy all evaluated directive dictionaries from self.__dict__ to the cloned or copied instances in both ApplicationBase.clone() and ObjectMixin.copy().
Ramble Performance Test MetricsResults produced with commit: 3377deb
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1756 +/- ##
===========================================
+ Coverage 94.07% 94.08% +0.01%
===========================================
Files 370 370
Lines 37399 37554 +155
===========================================
+ Hits 35182 35333 +151
- Misses 2217 2221 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors Ramble's directive system to support lazy evaluation on first access, introducing the DirectiveDictDescriptor class and removing the eager conversion of class attributes to instance attributes across all base classes. A comprehensive test suite has been added to verify lazy evaluation, inheritance, and isolation. The review feedback highlights critical inheritance issues where using getattr on classes or objects can mistakenly retrieve parent class attributes (such as evaluated directive dictionaries or preferred versions) instead of checking the subclass's own __dict__ directly, which would bypass subclass directive execution or raise incorrect errors.
1fadb66 to
87a882c
Compare
|
/gemini review |
7efbad1 to
2b398d1
Compare
|
/gemini review |
rfbgo
left a comment
There was a problem hiding this comment.
Two random questions:
- The bot reports a slow down from this. Is it it true? If so I think there are some places we might be able to improve perf slightly (eg optimized copies)
- I asked gemini to review this PR wrt "leaking" (it says it will leak). I kind of expect this is something you were already careful about, but I wanted to double check we believe this is indeed safe?
Great questions: For 1. it does seem to cause a slowdown on some perf tests. One reason is that previously the directive initialization cost are part of the startup, which wasn't counted by the benchmarking. And now with the lazy init, these init times are now part of the operations that are being benchmarked. So this is more or less an accounting thing. Other factors include the more works that are needed during copy (as we can no longer rely on the class-level attributes.) I should do a more thorough analysis though to see if any improvements are possible, and at least have a better breakdown of the timing. For 2. I did try to look for leaking, but I will do another pass to see where I missed. |
73a3649 to
85adeac
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
812fa9d to
bec5989
Compare
Convert eager directive execution into on-demand lazy evaluation via non-data descriptors, eliminating upfront convert_class_attributes deepcopies and isolating instance mutations. Signed-off-by: Lin Guo <linsword13@gmail.com>
bec5989 to
3377deb
Compare
The perf has been improved. The leaking should hopefully be addressed as well. |
Awesome, thank you for being willing to take those in. I know those were none trivial changes but I think the code is stronger now |
This is inspired by Spack's lazy directive (spack/spack#51881).
convert_class_attributessince now the lazy execution allows us to perform copy on first access